var bom = new Object();
bom.windowLearn = windowLearn;
function windowLearn()
{
    //获取窗口宽高
    var w=window.innerWidth
    || document.documentElement.clientWidth //针对ie8以下的包括8
    || document.body.clientWidth;//针对ie8以下的包括8

    var h=window.innerHeight
    || document.documentElement.clientHeight//针对ie8以下的包括8
    || document.body.clientHeight;//针对ie8以下的包括8
    
    //屏幕尺寸
    // alert(window.screen.availWidth);
    // alert(window.screen.availHeight);
    
    //location对象
    /*
    alert('hostname='+location.hostname);//返回主机地址
    alert('pathname='+location.pathname);//返回当前页的路径(绝对路径)
    alert('port='+location.port);//返回端口
    alert("href="+location.href);//返回链接地址
    */
    //location.href = "css2_demo.html"; //重定向到新的地址
    //location.assign("css2_demo.html");//重定向到新的地址
    
    //确认框
    var r = confirm("你确定要离开吗？");
    if(r)
    {
        alert('点击了确认按钮');
    }else
    {
        alert('点击了取消按钮');
    }
    
    //交互提示框
    var yourName = prompt("请输入你的名字:","yourName");    
    if(yourName!=null && yourName!="yourName")
    {
        alert("Hello "+yourName);
    }
}

function timerFunc()
{
    
}

function showCurTime()
{   
    var f = function ()
    {
        var p = getEle('time');
        var today = new Date();
        p.innerHTML="当前时间："+today.toLocaleString();
    }
    setInterval(f,1000);
}

/**设置和读取cookie在chrom浏览器下需要在服务器端访问才有效**/
function learnCookie()
{
    
}

function addCookieBtnEvts()
{
    var ids = ["setCookie","getCookie","newWin","checkWin"];
    for(var i in ids)
    {
        var btn = getEle(ids[i]);
        btn.addEventListener("click",onClickBtns);
    }   
    
}
var myWin;
function onClickBtns(evt)
{
    switch(evt.currentTarget.id)
    {
        case "setCookie":
            showHello();
            var text = getEle("cookieVal");           
            setCookie("myName",text.value,10*1000);
            break;
        case "getCookie":
            getCookie("myName");
            break;
        case "newWin": //打开一个新窗口            
            myWin=window.open("vue_demo_1.html");
            break;
        case "checkWin":
            checkWin();
            break;
    }
}

function checkWin()
{
    if(!myWin)
    {
        alert("窗口还没打开");
    }else
    {
        if(myWin.closed)
        {
            alert("窗口已经关闭");
        }else
        {
            alert("窗口已经打开了");
        }
    }
}


function setCookie(key,value,seconds)
{
    var now = new Date();
    alert(now.toGMTString());
    now.setTime(now.getTime()+seconds*1000);
    var str = key+"="+value+";expires="+now.toGMTString()+";"; //注意:某号是键值的结束
    alert("11="+document.cookie+",str="+str);
    document.cookie=str;
    alert("22="+document.cookie);
}

function getCookie(key)
{
    var cookieStr = document.cookie;
    alert("cookieStr="+cookieStr);
    var cookies = cookieStr.split(";");
    for(var i=0;i<cookies.length;i++)
    {
        var kvs = cookies[i].split("=");
        for(var key in kvs)
        {
            var v = kvs[key];
            if(v.trim()==key.trim())
            {
                return v;
            }
        }
    }
    return "";
}

function deleteCookie(key)
{
    var now = new Date();
    now.setTime(now.getTime()-1);
    document.cookie=key+"="+value+";expires="+now.toGMTString();
}
/**js有一个**/
function handlError(msg,url,line)
{
    var txt = "发现一个错误:\n错误信息是："+msg+"\n错误url:"+url+",错误行数:"+line;
    alert(txt);
}


